/**
    Die Ewigen Extension
    Copyright (C) 2011 DonKrieg @ sonkyu@googlemail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

(function($) {
    // we need some search strings to find the scans
    var SEARCH_FLEET                = "Flottenaufstellung von ";
    var SEARCH_ALLIANCE             = "Allianztag von ";
    var SEARCH_NEWS                 = "Nachrichten von ";
    var SEARCH_DEFENSE              = "Übersicht der Verteidigungsanlagen von ";
    var SEARCH_PROBE                = "Sondenbericht über ";

    var SEARCH_DEFENDER             = "Die Scanner haben eine verbündete Flotte von %1 Schiffen entdeckt. Ursprung: (%2), Reisezeit: %3";
    var SEARCH_DEFENDER_RETREAT     = "Eine Flotte zieht sich zurück. Flottengesinnung: verbündet Schiffe: %1 Ursprung: %2";

    /** scan class */
    $.ewigen.scan = function() {
    }

    $.fn.scanProbe = function() {
        var _playerName         = "";
        var _playerSystem       = "";
        var _playerRace         = "";

        var _playerCollectors   = "";

        var _playerPoints       = "";
        var _playerNumShips     = "";
        var _playerNumDefense   = "";

        return this.each(function(index) {
            var baseData = $(this).text();

            switch(index) {
                case 0: {   // player name and system
                        _playerName         = baseData.substring(SEARCH_PROBE.length,baseData.indexOf(" ("));
                        _playerSystem       = baseData.substring(baseData.indexOf("(")+1, baseData.indexOf(")"));

                        chrome.extension.sendRequest({
                            action: "storePlayerData",
                            key: "sde_"+_playerSystem+"_name",
                            value: _playerName
                        });
                        break;
                }
                case 4: {   // points
                        chrome.extension.sendRequest({
                            action: "storePlayerData",
                            key: "sde_"+_playerSystem+"_points",
                            value: baseData
                        });
                        break;
                }
                case 6: {   // number of ships
                        chrome.extension.sendRequest({
                            action: "storePlayerData",
                            key: "sde_"+_playerSystem+"_num_ships",
                            value: baseData
                        });
                        break;
                }
                case 8: {   // number of defense turrets
                        chrome.extension.sendRequest({
                            action: "storePlayerData",
                            key: "sde_"+_playerSystem+"_num_defenses",
                            value: baseData
                        });
                        break;
                }
                case 12: {  // collectors
                        chrome.extension.sendRequest({
                            action: "storePlayerData",
                            key: "sde_"+_playerSystem+"_collectors",
                            value: baseData
                        });
                        break;
                }
                case 14: {  // race
                        chrome.extension.sendRequest({
                            action: "storePlayerData",
                            key: "sde_"+_playerSystem+"_race",
                            value: baseData.substring(0, 1)
                        });
                        break;
                }
            }
        });
    }

    $.fn.scanFleet = function() {
        return this.each(function() {
            
        });
    }
})(jQuery)

